<template>
  <div class="main">
    <div class="collect">
      <span class="title">
        收藏
      </span>
      <el-divider></el-divider>
      <div v-loading="loading">
        <div v-if="collects.length > 0" class="collect-list">
          <div class="collect-list-item" v-for="collect in collects.slice((routePage - 1) * 5, routePage * 5)"
            :key="collect.id" @click="goRoute(collect.id)">
            <div class="collect-list-item-info">
              <div class="collect-list-item-cover">
                <img :src="collect.cover" alt="">
              </div>
              <div class="collect-list-item-text">
                <h1 class="collect-list-item-title">
                  {{ collect.title }}
                </h1>
                <div>
                  <span class="collect-list-item-description">
                    {{ collect.description }}
                  </span>
                </div>
                <div>
                  <span class="collect-list-item-author" @click="goUser(collect.author)">
                    <i class="el-icon-user-solid"></i>
                    {{ collect.authorName }}
                  </span>
                </div>
              </div>
            </div>
          </div>
          <el-pagination :hide-on-single-page="false" :total="collects.length" :page-size="5" layout="prev, pager, next"
            @current-change="changePage">
          </el-pagination>
        </div>
        <el-empty v-else description="这里什么也没有" style="margin-top:80px;"></el-empty>
      </div>
    </div>
  </div>
</template>

<script>
import request from '@/API/request';
import { Message } from 'element-ui';
export default {
  name: 'CollectInfo',
  data() {
    return {
      routePage: 1,
      collects: [],
      loading: true,
    }
  },
  methods: {
    goRoute(id) {
      this.$router.push({
        path: '/route',
        query: {
          id,
        },
      });
    },
    goUser(id) {
      this.$router.push({
        path: '/user',
        query: {
          id,
        },
      });
    },
    changePage(page) {
      this.routePage = page
    }
  },
  mounted() {
    request.get('/route/user/collect', {
      params: {
        id: this.$route.query.id,
      },
    }).then((res) => {
      if (res.data.code === 200) {
        this.collects = res.data.data;
      } else {
        Message({
          type: 'error',
          message: res.data.msg,
          customClass: 'message-global',
        });
      }
    }).catch((err) => {
      Message({
        type: 'error',
        message: err,
        customClass: 'message-global',
      });
    });
    this.loading = false;
  },
}
</script>

<style scoped>
.main {
  width: 100%;
  min-height: 520px;
  background-color: #fff;
  border-radius: 5px;
}

.collect {
  text-align: left;
  margin: 5px;
}

.title {
  display: block;
  font-size: 18px;
  line-height: 20px;
  font-weight: 500;
  margin: 10px;
}

.el-divider {
  margin: 10px 0;
}

.collect-list-item {
  border: solid 1px rgba(207, 205, 205, 0.842);
  padding: 3px;
  margin-top: 10px;
  margin-bottom: 10px;
  border-radius: 4px;
  transition: all 0.5s ease;
}

.collect-list-item:hover {
  border: solid 1px #409eff;
  box-shadow: 0 0 10px #409eff;
  cursor: pointer;
}

.collect-list-item-cover {
  display: inline-block;
  border-radius: 4px;
  position: relative;
  top: -15px;
  border-radius: 4px;
}

img {
  width: 200px;
  height: 140px;
  border-radius: 4px;
  object-fit: cover;
}

.collect-list-item-text {
  display: inline-block;
  margin-left: 10px;
  position: relative;
  text-align: left;
  height: 140px;
  top: 15px;
  width: 60%;
}

.collect-list-item-title {
  position: relative;
  top: 0px;
  display: inline-block;
  line-height: 35px;
  margin-left: 10px;
  margin-bottom: 0px;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.collect-list-item-author {
  position: relative;
  display: inline-block;
  font-size: 13px;
  margin-left: 10px;
  margin-top: 10px;
  top: 30px;
  border-radius: 1px;
  transition: all 0.3s ease;
}

.collect-list-item-author:hover {
  box-shadow: #235588 0px 0px 0px 1px;
  color: #235588;
  cursor: pointer;
}

.collect-list-item-description {
  display: inline-block;
  font-size: 13px;
  margin-left: 10px;
  margin-top: 10px;
  color: rgb(134, 134, 134);
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.el-pagination {
  text-align: center;
}
</style>